package com.af.community.smart.business

import android.os.Bundle
import android.view.MotionEvent
import com.af.community.smart.base.BaseActivity
import com.af.community.smart.base.oneClick
import com.af.community.smart.model.FormData
import com.af.community.smart.share.Const
import com.af.community.smart.view.FullyLinearLayoutManager
import kotlinx.android.synthetic.main.activity_patrol_house_detail.*
import kotlinx.android.synthetic.main.include_layout_map2.*
import net.idik.lib.slimadapter.SlimAdapter
import org.jetbrains.anko.startActivity

class PatrolHouseDetailActivity : BaseActivity() {

    private val list = ArrayList<FormData>()
    private lateinit var mTitle: String

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_patrol_house_detail)
        initTitle(title = "详情", name = "编辑")

        mTitle = intent.getStringExtra("title").orEmpty()
        mAdapter.updateData(list.apply {
            when (mTitle) {
                "住房" -> list.addAll(Const.listOne)
                "出租房" -> list.addAll(Const.listTwo)
                "宗教场所" -> list.addAll(Const.listThree)
                "医疗卫生单位" -> list.addAll(Const.listFour)
                "行政事业单位" -> list.addAll(Const.listFive)
                "新社会组织" -> list.addAll(Const.listSix)
                "新经济组织" -> list.addAll(Const.listSeven)
                "治安重点场所" -> list.addAll(Const.listEight)
                "安全生产重点企业" -> list.addAll(Const.listNine)
                "消防安全重点场所" -> list.addAll(Const.listTen)
                "学校" -> list.addAll(Const.listEleven)
                "企业" -> list.addAll(Const.listTwelve)
                "要害单位", "金融系统", "其他场所" -> list.addAll(Const.listThirteen)
            }
        })
    }

    override fun initTitle(title: String, name: String) {
        super.initTitle(title, name)
        patrol_list.apply {
            isNestedScrollingEnabled = false
            layoutManager = FullyLinearLayoutManager(baseContext)
        }

        mAdapter = SlimAdapter.create()
            .register<FormData>(R.layout.item_tax_list) { data, injector ->
                injector.text(R.id.item_tax_left, "${data.title}：")
                    .text(R.id.item_tax_right, data.content)
            }
            .attachTo(patrol_list)

        house_map.map.setOnMapTouchListener {
            patrol_scroll.requestDisallowInterceptTouchEvent(it.action != MotionEvent.ACTION_UP)
        }

        tvRight?.oneClick { startActivity<HouseAddActivity>("title" to mTitle) }
        bt_add.oneClick { startActivity<PatrolAddActivity>() }
    }

}
